import router from './index'
import {getUserToken,clearUserToken} from '@/utils/handleCookie'
import store from '../store/index'


router.beforeEach((to, from, next) => {
    // to and from are both route objects. must call `next`.
    if(getUserToken()){
        console.log('有token');
        next({replace:true});
    }else{
        console.log('没有token');
        //to 解释 为手动输入url
        if (to.path === '/login') {
            
            /* store.dispatch('login/Acs_clearUserToken')
            .then(res=>{
                clearUserToken();
                store.commit('login/CHANGE_TOKEN','');
            }); */
            next({replace:true})
        } else {
            next({path:'/login',replace:true})
        }  
    }
    
})